from logging import exception
from selenium.webdriver.support import expected_conditions
from time import sleep, strftime,localtime,time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from common.Utils import ForumDriver
from selenium.common.exceptions import NoSuchFrameException

class ForumReplymsg:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = ForumDriver.driver
        url = "http://127.0.0.1:58080/index.html"
        self.driver.get(url)

    def ReplyElement(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a").click()
        WebDriverWait(self.driver,15).until(
            expected_conditions.visibility_of_element_located((By.CSS_SELECTOR,"#index_message_offcanvasEnd"))
        )
        sleep(1)
        actual = self.driver.find_element(By.CSS_SELECTOR,"#offcanvasEndLabel").text
        print("actual:",actual)
        assert actual.strip() == "所有站内信"

    def ReplyFunc(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a").click()
        WebDriverWait(self.driver, 15).until(
            expected_conditions.visibility_of_element_located(
                (By.CSS_SELECTOR, "#index_div_message_list > div > div > div.col.text-truncate > a"))
        )
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div > div > div.col.text-truncate > a").click()
        WebDriverWait(self.driver,15).until(
            expected_conditions.visibility_of_element_located((By.CSS_SELECTOR,"#index_message_reply_modal > div > div"))
        )
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_detail_content")
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_message_reply").click()
        WebDriverWait(self.driver,15).until(
            expected_conditions.visibility_of_element_located((By.CSS_SELECTOR,"#index_message_reply_div"))
        )
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_reply_receive_content").send_keys("回复测试")
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message_reply").click()
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")